package models

import (
	"fmt"
	"time"
)

type jsonTime time.Time

//实现它的json序列化方法
func (j jsonTime) MarshalJSON() ([]byte, error) {
	var stamp = fmt.Sprintf("\"%s\"", time.Time(j).Format("2006-01-02 15:04:05"))
	return []byte(stamp), nil
}

func ParseJsonTime(time time.Time) jsonTime {
	return jsonTime(time)
}

type Book struct {
	Id           int        `gorm:"primary_key;AUTO_INCREMENT"json:"id"`
	BookName     string     `json:"bookName"`
	Author       string     `json:"author"`
	Price        float32    `json:"price"`
	TypeId       int        `json:"typeId"`
	PublishingId int        `json:"publishingId"`
	Status       int        `json:"status"`
	CreateTime   time.Time  `json:"createTime"`
	UpdateTime   time.Time  `json:"updateTime"`
	BookType     BookType   `grom:"ForeignKey:TypeId;AssociationForeignKey:TypeId"json:"bookType"`
	Publishing   Publishing `grom:"ForeignKey:PublishingId"json:"publishing"`
}

type BookType struct {
	TypeId   int    `gorm:"primary_key;AUTO_INCREMENT"json:"typeId"`
	TypeName string `json:"typeName"`
}
type Publishing struct {
	PublishingId   int    `gorm:"primary_key;AUTO_INCREMENT"json:"publishingId"`
	PublishingName string `json:"publishingName"`
}

type Borrow struct {
	BorrowId   int       `gorm:"primary_key;AUTO_INCREMENT"json:"borrowId"`
	Borrower   string    `json:"borrower"`
	BookId     int       `json:"bookId"`
	ReturnTime time.Time `json:"returnTime"`
	CreateTime time.Time `json:"createTime"`
	UpdateTime time.Time `json:"updateTime"`
	Status     int       `json:"status"`
	Remark     string    `json:"remark"`
	Book       Book      `grom:"ForeignKey:BookId"json:"book"`
}

func (Book) TableName() string {
	return "book"
}
func (BookType) TableName() string {
	return "book_type"
}
func (Publishing) TableName() string {
	return "publishing"
}
func (Borrow) TableName() string {
	return "borrow"
}
